﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace OpenST.Tools
{
    class RandomNoteSpray : BaseTool
    {
        private int Sprayspeed = 60;
        private int Radius = 10;

        private bool IsSpraying = false;
        

        public RandomNoteSpray(Composition comp, Game game)
            : base(comp, game)
        {

        }

        public override void MouseDown(int x, int y, int NoteNumber, string TileType, bool color)
        {
            IsSpraying = true;
            base.MouseDown(x, y, NoteNumber, TileType, color);
        }

        public override void MouseUp(int x, int y, int NoteNumber, string TileType, bool color)
        {
            IsSpraying = false;
            base.MouseUp(x, y, NoteNumber, TileType, color);
        }

        public override void Update(int x, int y, int NoteNumber, string TileType, bool color)
        {
            Random random = new Random();
            int xran = random.Next(-Radius, Radius);
            int yran = random.Next(-Radius, Radius);
            int note = random.Next(12);

            int newx = x + xran;
            int newy = y + yran;

            // Check if this position is valid, ignore this if not.
            if (newx < 0)
                return;

            if (newx > Composition.CompositionMaxSizeX - 1)
                return;

            if (newy > Composition.CompositionMaxSizeY - 1)
                return;

            if (newy < 0)
                return;

            if (IsSpraying)
            {

                composition.Tiles[newx, newy] = (Tiles.BaseTile)System.Reflection.Assembly.GetExecutingAssembly().CreateInstance(TileType, false, System.Reflection.BindingFlags.Default, null, new Object[] { game.Content }, null, null);
                composition.Tiles[newx, newy].color = color;
                composition.Tiles[newx, newy].NoteNumber = note;
            }
            
        }
    }
}
